<template>
	<view class="px-3">
		<view>
			<uni-list :border="false">
				<uni-list-item clickable title="账号安全" clickable link
					@click="$authJump('/pages/update-password/update-password')">
				</uni-list-item>
				<uni-list-item title="清除缓存" clickable @click="clearStorage">
					<view slot="footer">
						<view class="font">{{storageInfo.currentSize | changeSize}}</view>
					</view>
				</uni-list-item>
				<uni-list-item title="检查更新" clickable link>
				</uni-list-item>
				<uni-list-item title="当前版本" clickable>
					<view slot="footer">
						<view class="font">1.0.0</view>
					</view>
				</uni-list-item>
			</uni-list>
		</view>

		<main-button @click="loginOut">退出登录</main-button>
	</view>
</template>

<script>
	import tool from '@/common/tool.js'
	export default {
		data() {
			return {
				storageInfo: '',
				keys: []
			}
		},
		mounted() {
			this.getStoregeInfo()
		},
		filters: {
			changeSize: function(value) {
				return tool.bytesToSize(value);
			}
		},
		methods: {
			loginOut() {
				uni.showModal({
					content: '是否退出?',
					success: (res) => {
						if (res.confirm) {
							this.$api.loginOut({}).then(data => {
									this.$toast('退出成功')
									this.$store.dispatch('loginOut')
									uni.navigateBack({ delta: 1 })								
							})
						} else if (res.cancel) {
							return
						}
					}
				});
			},
			getStoregeInfo() {
				this.storageInfo = uni.getStorageInfoSync()
				this.keys = this.storageInfo.keys.filter(item => item !== 'userInfo')
				console.log(this.keys,'this.keys');
			},
			clearStorage() {
				uni.showModal({
					content: '是否清除缓存？',
					success: (res)=> {
						if (res.confirm) {
							console.log(this.keys,'this.keys');
							this.keys.forEach(item => {
								uni.removeStorageSync(item)
							})
							this.$toast('已清除缓存')
						} else if (res.cancel) {
							return
						}
					}
				});
			}
		}
	}
</script>

<style>

</style>
